{% extends 'oratk_app/master.html' %}
{% block tag_left %}
    {% include 'oratk_app/tag_left_user.html' %}
{% endblock %}
{% block title %}
    <title>ORATK</title>
{% endblock %}
{% block userinfo %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <form name="Form" role="search" action="/oratk_app/oratk_select_ora_shell" onsubmit="return validateForm()"
              target="_blank" method="POST">
            <h2 class="page-header">ORATK 工具</h2>
            {#    <div class="table-responsive">#}
            <div class="navbar-form navbar-left">
                &nbsp 选择实例: &nbsp
                <select class="selectpicker show-tick "  style="width:450px" data-live-search="true"   name="conn_string" id="conn_string">
                    <option id="def">--请选择实例名--</option>
                    <option id="usedb">使用脚本内实例</option>
                    {% for i in instanceinfo_result %}
                        <option id="a">{{ i.dbname }}={{ i.conn_string }}</option>
                    {% endfor %}
                </select>

                &nbsp 请输入shell参数: &nbsp
                <input id="args" type="text" style="width:300px;" name="args" class="form-control" >
                <button type="button" class="btn btn-default" id="btSearch">查询(本页展示）</button>
                <button type="submit" class="btn btn-default" id="btSearch_new">查询(新页展示）</button>
                <div id='exec_type_tag'>&nbsp</div>
                <div id="tab_detail" ></div>
            </div>
        </form>

    </div>

{% endblock %}

{% block script %}
    <script>

    //当点击（查询（新页展示））时
       function validateForm() {
           var select_conn = $('#conn_string').find("option:checked").attr("id")
           if (select_conn == 'def') {
               alert('请选择实例')
               return false;
           }
       }

        //当点击"查询(本页展示)时，输入框值检查及ajax异步调用"
        $('#btSearch').click(function () {
            var select_conn = $('#conn_string').find("option:checked").attr("id")
            if (select_conn == 'def') {
                alert('请选择实例')
                return;
            }


            //发送ajax请求
            $.ajax({
                type: "POST",
                data: {
                    'conn_string': $('#conn_string').val(),
                    'args': $('#args').val(),
                    'submit_id': 0
                },
                url: "/oratk_app/oratk_select_ora_shell", //后台处理函数的url
                cache: false,
                dataType: "html",
                success: function (result) {
                    $("#tab_detail").html(result);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    alert(XMLHttpRequest.status);
                    alert(XMLHttpRequest.readyState);
                    alert(textStatus);
                },
            })


        })

    </script>

{% endblock %}